﻿<Window x:Class="HRM.View.PParticipantDiolog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:HRM.CustomControl"
        DataContext="{Binding PPDialog, Source={StaticResource Locator}}"
        Title="{Binding Title}">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Skins/MainSkin.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="30" />
        </Grid.RowDefinitions>

        <Grid Grid.Row="0" Margin="5,0,0,5" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="110" />
            </Grid.ColumnDefinitions>
            <Grid Grid.Column="0" DataContext="{Binding SelectedItem,Mode=TwoWay}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="5"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="5"/>
                    <ColumnDefinition Width="150"/>
                    <ColumnDefinition Width="5"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="5"/>
                    <ColumnDefinition Width="150"/>
                </Grid.ColumnDefinitions>

                <StackPanel Grid.Row="0" Grid.ColumnSpan="10" Orientation="Horizontal" DataContext="{Binding DataContext, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}">
                    <RadioButton IsChecked="{Binding AddMode, Mode=TwoWay}" Margin="3">Thêm</RadioButton>
                    <RadioButton IsChecked="{Binding UpdateMode, Mode=TwoWay}" Margin="3">Sửa</RadioButton>
                </StackPanel>
                <TextBlock Grid.Row="1" Grid.Column="0" Text="Dự án" Style="{StaticResource TextBlockStyle}" />
                <ComboBox Grid.Row="1" Grid.Column="2" ItemsSource="{Binding Projects}" SelectedItem="{Binding ProjectSelected, Mode=TwoWay}" DataContext="{Binding DataContext, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding TenDuAn}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                
                <TextBlock Grid.Row="1" Grid.Column="4" Text="Ngày bắt đầu" Style="{StaticResource TextBlockStyle}" />
                <TextBlock Grid.Row="3" Grid.Column="4" Text="Ngày kết thúc" Style="{StaticResource TextBlockStyle}" />

                <DatePicker Grid.Row="1" Grid.Column="6" Text="{Binding NgayNhanChuc, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <DatePicker Grid.Row="3" Grid.Column="6" Text="{Binding NgayKetThuc, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </Grid>
            <Grid Grid.Column="1" Margin="10">
                <Image Source="{Binding Staff.AvatarSource}" Height="60"/>
            </Grid>
        </Grid>
        <Grid Grid.Row="1">
            <ToolBar>
                <Button Command="{Binding SaveCommand, UpdateSourceTrigger=PropertyChanged}">
                    <Button.Content>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="/Assets/Icons/save.png" Height="20"/>
                            <TextBlock Text="Lưu" VerticalAlignment="Center" Margin="3,0,3,0" />
                        </StackPanel>
                    </Button.Content>

                </Button>
                <Button Command="{Binding DeleteListCommand, UpdateSourceTrigger=PropertyChanged}">
                    <Button.Content>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="/Assets/Icons/delete.png" Height="20"/>
                            <TextBlock Text="Xóa" VerticalAlignment="Center" Margin="3,0,3,0" />
                        </StackPanel>
                    </Button.Content>
                </Button>

                <Button Command="{Binding RefreshCommand, UpdateSourceTrigger=PropertyChanged}">
                    <Button.Content>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="/Assets/Icons/sync.png" Height="20"/>
                            <TextBlock Text="Làm tươi" VerticalAlignment="Center" Margin="3,0,3,0" />
                        </StackPanel>
                    </Button.Content>
                </Button>

            </ToolBar>

            <TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,20,0" >
                                <Run Text="Total: " />
                                <Run Text="{Binding TotalItems}" FontWeight="Bold" />
                                <Run Text=" items" />
            </TextBlock>
        </Grid>

        <DataGrid Grid.Row="2" ItemsSource="{Binding ListEntities, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource DataGridStyle}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
            <DataGrid.Columns>
                <DataGridCheckBoxColumn Binding="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="False">
                    <DataGridCheckBoxColumn.HeaderTemplate>
                        <DataTemplate>
                            <CheckBox Command="{Binding PPDialog.CheckAllCommand}" DataContext="{StaticResource Locator}" CommandParameter="{Binding IsChecked, RelativeSource={RelativeSource Self}, UpdateSourceTrigger=PropertyChanged}"/>
                        </DataTemplate>
                    </DataGridCheckBoxColumn.HeaderTemplate>
                </DataGridCheckBoxColumn>
                <DataGridTextColumn Header="Chuyên ngành" Binding="{Binding ChuyenNganh}" Width="Auto" IsReadOnly="True"/>
                <DataGridTextColumn Header="Năm" Binding="{Binding Nam}" Width="Auto" IsReadOnly="True"/>
                <DataGridTextColumn Header="Ghi Chú" Binding="{Binding GhiChu}" Width="*" IsReadOnly="True"/>
                <DataGridTemplateColumn Header="Chức năng" Width="Auto">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="Xóa" Command="{Binding PPDialog.DeleteCommand}" DataContext="{StaticResource Locator}" CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>

        <local:PagingControl Grid.Row="3" FirstPageCommand="{Binding FirstPageCommand}" PreviosPageCommand="{Binding PreviosPageCommand}" NextPageCommand="{Binding NextPageCommand}" LastPageCommand="{Binding LastPageCommand}" PageIndex="{Binding PageIndex, Mode=TwoWay}" PageSize="{Binding PageSize, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" NumberOfPages="{Binding NumberOfPages, Mode=OneWay}"/>

    </Grid>
</Window>